package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.SupplierService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @description 供应商Controller
 */
@Controller
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 分页查询供应商
     * @param page
     * @param rows
     * @param supplierName
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    @RequiresPermissions(value = "供应商管理")// 有供应商管理菜单权限的才给予调用
    public Map<String,Object> list(Integer page, Integer rows, String supplierName){
        return supplierService.list(page, rows,supplierName);
    }

    /**
     * 添加或修改供应商信息
     * @param supplier
     * @return
     */
    @PostMapping(value = "/save")
    @ResponseBody
    @RequiresPermissions(value = "供应商管理")
    public ServiceVO save(Supplier supplier) {
        return supplierService.save(supplier);
    }

    /**
     * 删除供应商信息
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    @RequiresPermissions(value = "供应商管理")
    public ServiceVO delete(String ids) {
        String[] id = ids.split(",");
        return supplierService.delete(id);
    }
}
